import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/unit/screen/screen_utility.dart';

class EmailLogin extends StatefulWidget {

  final Function emailCallBack;
  final Function emailLoginCallBack;
  ///=0登录
  ///=1找回密码
  int type;

   EmailLogin({Key? key, required this.emailLoginCallBack, required this.emailCallBack,this.type = 0}) : super(key: key);

  @override
  State<EmailLogin> createState() => _EmailLoginState();
}

class _EmailLoginState extends State<EmailLogin> {


  final TextEditingController _emailController = TextEditingController();
  final TextEditingController _controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(child: TextField(
              onChanged: (text){
                _handleInput('username', text);
              },
              controller: _emailController,
              style: StandardTextStyle.inputHintStyle,
              maxLines: 1,
              inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9\W]'))],
              decoration: InputDecoration(
                  hintText: '请输入邮箱号',
                  hintStyle: StandardTextStyle.inputHintStyle,
                  border: InputBorder.none
              ),
            ))
          ],),
        Divider(height: 0.5.H, color: ColorPlate.white.withOpacity(0.15),),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(child: SizedBox(
              height: 67.0.H,
              child: TextField(
                onChanged: (text){
                  _handleInput('password', text);
                },
                controller: _controller,
                style: StandardTextStyle.inputHintStyle,
                maxLines: 1,
                inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9\W]'))],
                decoration: InputDecoration(
                    hintText: widget.type==0?'请输入密码':'请输入验证码',
                    hintStyle: StandardTextStyle.inputHintStyle,
                    border: InputBorder.none
                ),
              ),)),
            GestureDetector(
              onTap: () {
                widget.emailCallBack.call();
              },
              child:Text(widget.type==0?"忘记密码":'获取验证码',style: StandardTextStyle.textBlue16Style,),
            )
          ],),
        Divider(height: 0.5.H, color: ColorPlate.white.withOpacity(0.15),),
      ],
    );
  }


  var map = {'username': '', 'password': ''};

  void _handleInput(String key, String text) {
    map[key] = text;
    widget.emailLoginCallBack.call(map);
  }
}
